home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / wildhearts_stage_dive.swf / scripts / __Packages / Snd.as next >
Text File  |  2011-08-19  |  3KB  |  126 lines

  1. class Snd extends Sound
  2. {
  3.    static var FADE_RATE = 100;
  4.    function Snd(targ, sndman)
  5.    {
  6.       super(targ);
  7.       this.target = !targ ? _root : targ;
  8.       this.manager = sndman;
  9.    }
  10.    function switchSound(id, loops)
  11.    {
  12.       var _loc3_ = this.position;
  13.       super.stop();
  14.       super.attachSound(id);
  15.       this.start(_loc3_ % this.duration / 1000,loops);
  16.    }
  17.    function fade(dVol, tVol, handler)
  18.    {
  19.       this.onFadeComplete = handler;
  20.       if(this.fId)
  21.       {
  22.          this.stopFade(this.fId);
  23.       }
  24.       this.fId = setInterval(this,"changeVolTowards",Snd.FADE_RATE,dVol * (Snd.FADE_RATE / 1000),tVol,true);
  25.    }
  26.    function fadeBy(dVol, t, handler)
  27.    {
  28.       this.onFadeComplete = handler;
  29.       if(this.fId)
  30.       {
  31.          this.stopFade(this.fId);
  32.       }
  33.       if(t > 0)
  34.       {
  35.          this.fId = setInterval(this,"changeVolTowards",Snd.FADE_RATE,dVol * (Snd.FADE_RATE / 1000),dVol * t,true);
  36.       }
  37.    }
  38.    function fadeTo(tVol, t, handler)
  39.    {
  40.       this.onFadeComplete = handler;
  41.       if(this.fId)
  42.       {
  43.          this.stopFade(this.fId);
  44.       }
  45.       if(t > 0)
  46.       {
  47.          var _loc3_ = (tVol - this.getVolume()) / t;
  48.          trace("fadeTo: " + tVol + ", " + this.getVolume() + ", " + _loc3_);
  49.          this.fId = setInterval(this,"changeVolTowards",Snd.FADE_RATE,_loc3_,tVol,true);
  50.       }
  51.       else
  52.       {
  53.          this.setVolume(tVol);
  54.       }
  55.    }
  56.    function changeVolTowards(dVol, tVol, fading)
  57.    {
  58.       var _loc2_ = this.getVolume();
  59.       if(Math.abs(dVol) < Math.abs(tVol - _loc2_))
  60.       {
  61.          this.changeVolume(dVol);
  62.       }
  63.       else
  64.       {
  65.          this.setVolume(tVol);
  66.          if(fading)
  67.          {
  68.             this.stopFade();
  69.          }
  70.       }
  71.    }
  72.    function stopFade()
  73.    {
  74.       if(this.fId)
  75.       {
  76.          clearInterval(this.fId);
  77.          delete this.fId;
  78.          this.onFadeComplete();
  79.          delete this.onFadeComplete;
  80.       }
  81.    }
  82.    function positionSound(a, d, f, t)
  83.    {
  84.       if(d < f)
  85.       {
  86.          t = !isNaN(t) ? (t >= 0 ? t : 0) : 100;
  87.          d = d >= 1 ? d : 1;
  88.          var _loc4_ = 1 / (d / f * 100);
  89.          this.setVolume(Math.ceil(_loc4_ * t));
  90.          this.setPan((- Math.sin(a)) * 100);
  91.       }
  92.       else
  93.       {
  94.          this.setVolume(0);
  95.       }
  96.    }
  97.    function positionSoundLinear(a, d, f, t)
  98.    {
  99.       if(d < f)
  100.       {
  101.          t = !isNaN(t) ? (t >= 0 ? t : 0) : 100;
  102.          this.setVolume((f - d) / f * t);
  103.          this.setPan((- Math.sin(a)) * 100);
  104.       }
  105.       else
  106.       {
  107.          this.setVolume(0);
  108.       }
  109.    }
  110.    function changeVolume(n)
  111.    {
  112.       this.setVolume(this.getVolume() + n);
  113.    }
  114.    function remove()
  115.    {
  116.       super.stop();
  117.       delete this.manager.sounds[this.target.getDepth()];
  118.       this.target.removeMovieClip();
  119.       false;
  120.    }
  121.    function toString()
  122.    {
  123.       return "(target=" + this.target + ")";
  124.    }
  125. }
  126.